/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Thread;

import RemoteDesktop.ConnectRemote;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

/**
 *
 * @author ThuyHuynh
 */
public class ConnectName extends Thread{
    ServerSocket ss;
    ArrayList<StructClient> arrClient = new ArrayList<StructClient>();
    Connection cn;
    JTable jTable1;
    JPanel scrImages;
    public ConnectName(int port,JTable jtb,JPanel jsp) throws IOException{
        ss=new ServerSocket(port);
        this.jTable1=jtb;
        this.scrImages=jsp;
    }
    @Override
    public void run(){
        while(true){
            try {
                Socket soc=ss.accept();
                ObjectInputStream in=new ObjectInputStream(soc.getInputStream());
                ObjectOutputStream out=new ObjectOutputStream(soc.getOutputStream());
                String name = SendComputerName.SendName(in, out);//lay ten ma tu client goi ve
                StructClient client = new StructClient(name, name, 1);//tao ra 1 cau truc struct client de chua name,ip(chua lam),trang thai
                arrClient.add(client);
                cn = new Connection(1234, jTable1,arrClient);
                cn.start();
                ConnectFile cnf = new ConnectFile(4567);
                cnf.start();
                ConnectFile_Tree cnt = new ConnectFile_Tree(4568);
                cnt.start();

                ConnectImages cimg = new ConnectImages(4569,scrImages,client);
                cimg.start();

                ConnectShellSV cnn = new ConnectShellSV(6778);
                cnn.start();
                new ConnectRemote(5678).start();
                new ThreadCon(2345).start();
            } catch (IOException ex) {
                Logger.getLogger(ConnectName.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
